package com.itcanteen.medical.patient.util;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.model.PutObjectRequest;

import java.io.InputStream;

/**
 * 阿里云OSS 上传图片 工具类
 * @author 1804A-TeamOne
 * @date 2020-12-17 19:12
 */
/**
 * @author 六金
 */
public class OSSUploadUtils {

   public static void uploadFile(String bucket,InputStream inputStream,String fileName,String endpoint,String accessKeyId,String accessKeySecret){

       OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);

       PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, fileName, inputStream);

       ossClient.putObject(putObjectRequest);

       //返回oss图片路径
       String url=endpoint.replaceFirst("http://","http://"+bucket +".")+"/"+fileName;
       System.out.println(url);

       ossClient.shutdown();

   }

}
